package com.study.jdbc.junit;

import java.sql.Date;
import java.util.List;

import org.junit.Test;

import com.study.jdbc.crud.ItemCRUD;
import com.study.jdbc.crud.ItemCRUDImpl;
import com.study.jdbc.domain.Item;
import com.study.jdbc.factory.BeanFactory;

/**
* @Name: ItemCRUDTest
* @Description: 商品信息CRUD测试类
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-2-16 下午3:02:34 
* @Version: V1.0
 */
public class ItemCRUDTest {
	
	@Test
	public void testFindItemById() {
		ItemCRUD itemCRUD = BeanFactory.getInstance().getItemCRUDImpl() ;
		Item item = itemCRUD.findItemById(2) ;
		System.out.println(item);
	}
	
	@Test
	public void testFindAllItems() {
		ItemCRUD itemCRUD = new ItemCRUDImpl() ;
		List<Item> items = itemCRUD.findAllItems() ;
		for (Item item : items) {
			System.out.println(item);
		}
	}
	
	@Test
	public void testInsertItem() {
		ItemCRUD itemCRUD = new ItemCRUDImpl() ;
		Item item = new Item() ;
		item.setId(6) ;
		item.setName("手机2") ;
		item.setPrice(5000.0f) ;
		item.setDetail("用着很爽！！！！！") ;
		item.setCreatetime(new Date(12321431L)) ;
		itemCRUD.insertItem(item) ;
		System.out.println("插入成功！");
	}
	
	@Test
	public void testUpdateItem() {
		ItemCRUD itemCRUD = new ItemCRUDImpl() ;
		Item item = new Item() ;
		item.setId(0) ;
		item.setName("44444") ;
		item.setPrice(1230.0f) ;
		item.setDetail("用着很爽！！！！！") ;
		item.setPic("1.jpg") ;
		item.setCreatetime(new Date(1342112L)) ;
		itemCRUD.updateItem(item) ;
		System.out.println("更新成功！");
	}
	
	@Test
	public void testDeleteItemById() {
		ItemCRUD itemCRUD = new ItemCRUDImpl() ;
		itemCRUD.deleteById(6) ;
		System.out.println("删除成功！");
	}

}
